<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" import="java.sql.*"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<style type="text/css">
        #style-c
			{
				font-family: "Lucida Sans Unicode", "Lucida Grande", Sans-Serif;
				font-size: 12px;
				margin: 45px;
				width: 480px;
				text-align: center;
				border-collapse: collapse;
				border-top: 7px solid #9baff1;
				border-bottom: 7px solid #9baff1;
			}
			#style-c th
			{
				font-size: 13px;
				font-weight: normal;
				padding: 8px;
				background: #e8edff;
				border-right: 1px solid #9baff1;
				border-left: 1px solid #9baff1;
				color: #039;
			}
			#style-c td
			{
				padding: 8px;
				background: #e8edff; 
				border-right: 1px solid #aabcfe;
				border-left: 1px solid #aabcfe;
				color: #669;
			}

		</style>
<body>
	<%
	try {
		//第一步: 加载驱动程序
	Class.forName("com.mysql.jdbc.Driver");
		//连接数据库,不要忘了设置编码格式为 utf-8
	String url = "jdbc:mysql://localhost:3306/stu?useUnicode=true&characterEncoding=utf8";
		//用户名root
	String user = "root";
		//数据库密码:123456
	String pass = "123456";
		//连接数据库
	Connection con = DriverManager.getConnection(url, user, pass);
	Statement st = con.createStatement();
	ResultSet rs = st.executeQuery("select * from student1");
	%>
	<table id="style-c">
		<tr>
		<td>学号</td>
		<td>系部</td>
		<td>性别</td>
		<td>年龄</td>
		<td>姓名</td>
		</tr>
	<%
		while(rs.next()){
	%>
		<tr>
		<td><%=rs.getString("sno") %></td>
		<td><%=rs.getString("sdep") %></td>
		<td><%=rs.getString("ssex") %></td>
		<td><%=rs.getInt("sage") %></td>
		<td><%=rs.getString("sname") %></td>
		</tr>
	<%}
	 rs.close();
	 st.close();
	//ps.close();
	con.close();
} catch (ClassNotFoundException e) {
	
	e.printStackTrace();
} catch (SQLException e) {
	
	e.printStackTrace();
}
	
	%>
		
	</table>
</body>
</html>